package com.htc.dao;

import java.sql.Date;
import java.sql.SQLException;
import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.htc.model.Order;
import com.htc.model.Product;


public interface OrderMapper{

	@Insert("insert into `order`(oid,money,recipients,tel,address,state,ordertime,uid,orderNo)"
			+ " values(#{oid},#{money},#{recipients},#{tel},#{address},#{state},now(),#{uid},#{orderNo})")
	@Options(
		    useGeneratedKeys = true,
		    keyProperty = "oid"
    )
	public int placeOrder(Order order);

	@Update("update `order` set state=#{state} where oid=#{oid}")
	public int updateOrderStateByOid(@Param("oid")String oid, @Param("state")int state);

	@Select("select * from `order` where oid=#{oid}")
	public Order findOrderById(String oid);

	@Select("select * from `order` ${where} ")
	public List<Order> findAllOrder(@Param("where")String where);

	@Select("select * from `order` where uid=#{uid}")
	public List<Order> findOrderByUid(int uid); 
	
	@Select("select * from `order` ${where}")
	public List<Order> queryList(@Param("where")String where);
	
	@Select("select product.*,orderitem.buynum buynum from orderitem,product where orderitem.oid=#{oid} and product.pid=orderitem.pid")
	public List<Product> queryOrderDetail(@Param("oid")int oid);
	
}
